import { defineStore } from "pinia";
import type { IAnalysisState } from "./type.d.ts";
import {
  getAmountListData,
  getCatetoryGoodsCount,
  getCitiesGoodsCount,
  getGoodsFavorCount, getGoodsSalesCount
} from "@/services/modules/analysis";

const useAnalysisStore = defineStore("analysis", {
  state: (): IAnalysisState => ({
    amountList: [],
    goodsCategoryCount: [],
    citiesGoodsCount: [],
    favorsCount: [],
    salesCount: []
  }),
  actions: {
    async fetchAmountListDataAction() {
      this.getAmountListDataAction()
      this.getCategoryGoodsCountAction()
      this.getCitiesGoodsCountAction()
      this.getGoodsFavorCountAction()
      this.getGoodsSalesCountAction()
    },
    async getAmountListDataAction() {
      const amountRes = await getAmountListData()
      this.amountList = amountRes.data
    },
    async getCategoryGoodsCountAction() {
      const goodsCategoryCountRes = await getCatetoryGoodsCount()
      this.goodsCategoryCount = goodsCategoryCountRes.data
    },
    async getCitiesGoodsCountAction() {
      const citesRes = await getCitiesGoodsCount()
      this.citiesGoodsCount = citesRes.data
    },
    async getGoodsFavorCountAction() {
      const favorsRes = await getGoodsFavorCount()
      this.favorsCount = favorsRes.data
    },
    async getGoodsSalesCountAction() {
      const saleRes = await getGoodsSalesCount()
      this.salesCount = saleRes.data
    }
  }
});

export default useAnalysisStore;
